from selenium import webdriver
import time
import sys

# 方法1
# driver = webdriver.Chrome()
#
# driver.get("https://www.baidu.com/")
# time.sleep(3)
# driver.maximize_window()
# driver.find_element_by_class_name("s_ipt").send_keys("学习python")
#
#
# time.sleep(3)
# driver.find_element_by_partial_link_text("登录").click()
# time.sleep(2)
# driver.find_element_by_id("TANGRAM__PSP_10__footerULoginBtn").click()
# driver.find_element_by_id("TANGRAM__PSP_10__userName").send_keys("du0419")
# driver.find_element_by_id("TANGRAM__PSP_10__password").send_keys("du403516887!")
# driver.find_element_by_id("TANGRAM__PSP_10__submit").click()

#方法2
def login_test():
    driver = webdriver.Chrome()
    driver.get("http://www.baidu.com/")
    #点击登录链接
    time.sleep(2)
    driver.find_element_by_xpath("//*[@id='u1']/a[7]").click()
    #点击用户登录按钮
    time.sleep(2)

    # driver.find_element_by_class_name("tang-pass-footerBar").find_element_by_css_selector("#TANGRAM__PSP_10__footerULoginBtn").click()
    driver.find_element_by_xpath("//*[@id='TANGRAM__PSP_10__footerULoginBtn']").click()
    #输入用户名
    time.sleep(2)
    driver.find_element_by_id("TANGRAM__PSP_10__userName").send_keys("du0419")
    #输入密码
    time.sleep(2)
    driver.find_element_by_id("TANGRAM__PSP_10__password").send_keys("123456")
    #点击登录按钮
    time.sleep(2)
    driver.find_element_by_id("TANGRAM__PSP_10__submit").click()
    time.sleep(5)

    try:
        driver.find_element_by_link_text("找回密码")
        print("密码错误")
    except:
        print("登录成功")

if __name__=='__main__':
    login_test()






